package com.hmyd.hmyd_android.dialog;

import com.hmyd.hmyd_android.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class ConfirmInvestmentDialog extends Dialog implements android.view.View.OnClickListener {
	// 标名
	private TextView investment_name;
	// 预期年化利率
	private TextView investment_rate;
	// 锁定期
	private TextView investment_time;
	// 投资金额
	private TextView investment_amount;
	// 使用小惠钱包
	private TextView investment_h;
	// 使用优惠券
	private TextView investment_coupon;
	// 实际支付
	private TextView investment_pay;
	
	private View content_h;
	private View content_coupon;
	
	String name;
	String rate;
	String time;
	String amount;
	String h;
	String coupon;
	String pay;

	private View mClosed;
	private Button ok;
	private Button cancle;

	private String okStr;
	private String cancleStr;

	private NormalDialogListener mOnclickListener;

	public ConfirmInvestmentDialog(Context context) {
		super(context);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

	}

	public ConfirmInvestmentDialog(Context context, int theme,
			NormalDialogListener onclickListener, 
			String name, String rate, String time,
			String amount, String h, String coupon, String pay,
			String okstring,String cancleString) {
		super(context, theme);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		mOnclickListener = onclickListener;
		
		this.name = name;
		this.rate = rate;
		this.time = time;
		this.amount = amount;
		this.h = h;
		this.coupon = coupon;
		this.pay = pay;
		
		okStr = okstring;
		cancleStr = cancleString;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_normal_confirminvest);

		content_h = findViewById(R.id.content_h);
		content_coupon = findViewById(R.id.content_coupon);
		
		investment_name = (TextView) findViewById(R.id.investment_name);
		investment_rate = (TextView) findViewById(R.id.investment_rate);
		investment_time = (TextView) findViewById(R.id.investment_time);
		investment_amount = (TextView) findViewById(R.id.investment_amount);
		investment_h = (TextView) findViewById(R.id.investment_h);
		investment_coupon = (TextView) findViewById(R.id.investment_coupon);
		investment_pay = (TextView) findViewById(R.id.investment_pay);
		
		if (!TextUtils.isEmpty(name)) {
			investment_name.setText(name);
		}
		
		if (!TextUtils.isEmpty(rate)) {
			investment_rate.setText("预期年化利率： "+rate);
		}
	
		if (!TextUtils.isEmpty(time)) {
			investment_time.setText("锁定期： "+time);
		}
	
		if (!TextUtils.isEmpty(amount)) {
			investment_amount.setText(amount);
		}
	
		if (!TextUtils.isEmpty(h)) {
			if (Double.parseDouble(h) > 0) {
				h = "-"+h;
			}
			investment_h.setText(h);
		} else {
			content_h.setVisibility(View.GONE);
		}
	
		if (!TextUtils.isEmpty(coupon)) {
			if (Double.parseDouble(coupon) > 0) {
				coupon = "-"+coupon;
			}
			investment_coupon.setText(coupon);
		}else {
			content_coupon.setVisibility(View.GONE);
		}
	
		if (!TextUtils.isEmpty(pay)) {
			investment_pay.setText(pay);
		}

		ok = (Button) findViewById(R.id.ok);
		ok.setOnClickListener(this);

		cancle = (Button) findViewById(R.id.cancle);
		cancle.setOnClickListener(this);

		if (!TextUtils.isEmpty(okStr)) {
			ok.setText(okStr);
		}
		
		if (!TextUtils.isEmpty(cancleStr)) {
			cancle.setText(cancleStr);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.closed:
			mOnclickListener.closed();
			cancel();
			break;
		case R.id.ok:
			mOnclickListener.ok();
			cancel();
			break;
		case R.id.cancle:
			mOnclickListener.cancle();
			cancel();

			break;
		default:
			break;
		}
	}

	public void setName(String name) {
		if (!TextUtils.isEmpty(name)) {
			investment_name.setText(name);
		}
	}
}
